<template>
  <div class="base-echart">
    <div ref="echartDivRef" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, defineProps, withDefaults, watchEffect } from 'vue'
import useEchart from '../hooks/useEchart'

// 定义props
// defineProps({
//   width: String,
//   height: String
// })
const props = withDefaults(
  defineProps<{
    options: any
    width?: string
    height?: string
  }>(),
  {
    width: '100%',
    height: '360px'
  }
)

const echartDivRef = ref<HTMLElement>()

onMounted(() => {
  const { setOptions } = useEchart(echartDivRef.value!)
  watchEffect(() => {
    setOptions(props.options)
  })
  // const ecahrtInstance = echarts.init(echartDivRef.value)

  // ecahrtInstance.setOption(props.options)
})
</script>

<style scoped>
.base-echart {
  height: 300px;
}
</style>
